package com.wxw.BaseLibrary.component;

import android.content.Context;
import android.graphics.Color;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Created by david on 2014-06-10.
 */
public class SimpleTextItemWithShadowView extends LinearLayout {
    private LinearLayout linearLayout;
    private TextView textView;
    private TextView tvLine1,tvLine2;
    private int verticalMargin = 10;
    private int shadowColor = Color.parseColor("#8a9089");

    public int getShadowColor() {
        return shadowColor;
    }

    public void setShadowColor(int shadowColor) {
        this.shadowColor = shadowColor;
        tvLine1.setBackgroundColor(shadowColor);
        tvLine2.setBackgroundColor(shadowColor);
    }

    public int getVerticalMargin() {
        return verticalMargin;
    }

    public void setVerticalMargin(int verticalMargin) {
        this.verticalMargin = verticalMargin;
        FrameLayout.LayoutParams layoutParams1 = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.WRAP_CONTENT);
        layoutParams1.setMargins(verticalMargin,verticalMargin,verticalMargin,verticalMargin);
        AbsListView.LayoutParams layoutParams2 = new AbsListView.LayoutParams(layoutParams1);
        setLayoutParams(layoutParams2);
    }

    public TextView getTextView() {
        return textView;
    }

    public SimpleTextItemWithShadowView(Context context) {
        super(context);
        setBackgroundColor(Color.WHITE);
        setOrientation(VERTICAL);

        FrameLayout.LayoutParams layoutParams1 = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.WRAP_CONTENT);
//        layoutParams1.setMargins(verticalMargin,verticalMargin,verticalMargin,verticalMargin);
        AbsListView.LayoutParams layoutParams2 = new AbsListView.LayoutParams(layoutParams1);
        setLayoutParams(layoutParams2);
        linearLayout = new LinearLayout(context);
        linearLayout.setGravity(Gravity.CENTER);
        linearLayout.setOrientation(HORIZONTAL);
        addView(linearLayout, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
//        ((LinearLayout.LayoutParams)linearLayout.getLayoutParams()).setMargins(5, verticalMargin, 0, verticalMargin);

        textView = new TextView(context);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(verticalMargin, verticalMargin, verticalMargin, verticalMargin);
        layoutParams.weight = 1;
        textView.setLayoutParams(layoutParams);
        textView.setBackgroundColor(Color.TRANSPARENT);
        textView.setTextColor(Color.BLACK);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
        linearLayout.addView(textView);

        tvLine1 = new TextView(context);
        tvLine1.setBackgroundColor(shadowColor);
        layoutParams = new LinearLayout.LayoutParams(3, ViewGroup.LayoutParams.MATCH_PARENT);
        tvLine1.setLayoutParams(layoutParams);
        linearLayout.addView(tvLine1);

        tvLine2 = new TextView(context);
        tvLine2.setBackgroundColor(shadowColor);
        layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 3);
//        layoutParams.setMargins(5, 0, 5, 10);
        tvLine2.setLayoutParams(layoutParams);
        addView(tvLine2);
    }
}
